<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/rest/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>

<style>
#jobInfo{
   min-height:100px;
   overflow-y:auto;
   max-height:300px;
}
</style>

<body>

<fieldset class="layui-elem-field layui-field-title">
  <legend style="text-align: center;">数据生成器配置</legend>
</fieldset>
 
<form class="layui-form" action="" lay-filter="form_config">
  <div class="layui-form-item">
  <div class="layui-inline">
      <label class="layui-form-label" style="width: 150px;">生成速率</label>
      <div class="layui-input-inline">
        <input type="text" name="volume" placeholder="1000（每秒）" lay-verify="" autocomplete="off" class="layui-input" style="width: 150px;">
      </div>
    </div>
    
    <div class="layui-inline">
      <label class="layui-form-label" style="width: 150px;">错误率</label>
      <input type="text" name="error_rate" placeholder="0.25（千分制）" lay-verify="" autocomplete="off" class="layui-input" style="width: 150px;">
      <div class="layui-input-inline">
      </div>
    </div>
  </div>
  <div class="layui-form-item">
  <!-- <label class="layui-form-label" style="width: 150px;">storm拓扑</label> -->
    <label class="layui-form-label" style="width: 150px;">worker节点数</label>
      <input type="text" name="worker" placeholder="1（默认）" autocomplete="off" style="width: 150px;float:left;" class="layui-input">
    
    <label class="layui-form-label" style="width: 150px;">spout并行度</label>
      <input type="text" name="spout" placeholder="2（默认）" autocomplete="off" style="width: 150px;float:left;"  class="layui-input">
      
       <label class="layui-form-label" style="width: 150px;">bolt并行度</label>
      <input type="text" name="bolt" placeholder="2（默认）" autocomplete="off" style="width: 150px;float:left;"  class="layui-input">
    
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label" style="width: 150px;">运行模式</label>
    <div class="layui-input-block" style="margin-left:150px;">
      <input type="radio" name="mode" value="local" title="本地模式" checked="">
      <input type="radio" name="mode" value="cluster" title="集群模式">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label"  style="width: 150px;">JOB开关</label>
    <div class="layui-input-block" style="margin-left:150px;">
      <input type="checkbox" name="status" lay-skin="switch" lay-filter="status" lay-text="ON|OFF">
    </div>
  </div>
  
  <div class="layui-form-item">
    <div class="layui-input-block" style="text-align: center;margin-left:0px;">
      <button class="layui-btn" lay-submit=""  lay-filter="submit_conf">立即提交</button>
    </div>
  </div>
</form>


<div style="padding: 20px; background-color: #F2F2F2;">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md6" style="width:80%;margin-left:50px;">
      <div class="layui-card">
        <div class="layui-card-header">Job运行信息</div>
        <div class="layui-card-body" id = "jobInfo">
        </div>
      </div>
    </div>
  </div>
</div>   
<div id="jobInfo"></div>        
<script src="/rest/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>

layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  //日期
  laydate.render({
    elem: '#date'
  });
  laydate.render({
    elem: '#date1'
  });
  
  //创建一个编辑器
  var editIndex = layedit.build('LAY_demo_editor');
 
 /*  //自定义验证规则
  form.verify({
    title: function(value){
      if(value.length < 5){
        return '标题至少得5个字符啊';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  }); */
  
  //监听指定开关
  form.on('switch(status)', function(data){
  console.log(data)
 // killjob
 	if(!this.checked){
 		 $.ajax({
 		    url: '/rest/highEchart/killjob',
 		    timeout:60000,
 		    data: {name:'test'},
 		    success: function(data) {
	 		    	console.log(data)
	 		   	document.getElementById("jobInfo").innerHTML = data + "<br>";
 		    },
 		    cache: false
 		  });
 	}
  /*   layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
      offset: '6px'
    }); */
   // layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
  });
  
  //监听提交
  form.on('submit(submit_conf)', function(data){
	/*  {"volume":"1000","worker":"1","spout":"1","bolt":"1","mode":"local"} */ 
	console.log(data)
	 $.ajax({
	    url: '/rest/highEchart/genconf',
	    data: {volume:data.field.volume, error_rate:data.field.error_rate, worker:data.field.worker,spout:data.field.spout,bolt:data.field.bolt,mode:data.field.mode},
	    success: function(data) {
	    	console.log(data)
	  //  	var points = JSON.parse(point.value)
	     //表单赋值
  		form.val('form_config', {"status": true  })
  		document.getElementById("jobInfo").innerHTML = data + "<br>";
	    },
	    cache: false
	  });
    /* layer.alert(JSON.stringify(data.field), {
      title: '最终的提交信息'
    }) */
    return false;
  });
 
  
  
});
</script>

</body>
</html>